Skip to content

fix(studio): a sealed crop draws a layer's insets at its own scale and follows a seek - #8451

Merged
miguel-heygen merged 12 commits into
mainfrom
fix/sealed-crop-scaled-before-press
Nov 22, 2026
Merged

miguel-heygen merged 12 commits into
mainfrom
fix/sealed-crop-scaled-before-press

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

What

In a sealed preview (Studio cannot script the frame), a selected layer's crop frame now draws its insets at the layer's own scale and size, as an unsealed preview does, in two cases that were wrong before:

  • Selected without a press on the canvas (from the Layers panel, the timeline, the agent, or after an undo swaps the element): the crop insets were drawn at the overlay's zoom alone, as if the layer had no scale of its own, until a press measured it.
  • After a seek with no pointer on the page (a timeline key, an agent seek): the selection box and crop frame stayed at the layer's size before the seek until the overlays' idle poll, which backs off to 4 s. An unsealed preview redraws them at once.

Why

A sealed preview's stand-in has no size of its own, so the crop frame needs the layer's untransformed size from the frame. Only a press read it. Separately, the editor overlays wake on a preview's playhead posts only from Studio's own origin, but a sealed frame posts from an opaque origin, so after a seek they waited for the idle poll.

Related work

Refs #8310 (the same gap for a turned layer's crop frame before any press).

How

  • DomEditCropHandles: while a stand-in is selected and not dragged, it asks the frame for the same gesture-start read a press already makes (readCropFrameStart), once on selection and again whenever its overlay size changes. One read at a time; a change during a read asks once more when it lands. A new selection or a press drops a read still out, so a reply sent for an earlier selection never replaces a newer one. No new message type.
  • bridgePlayback: the check "a post from a preview frame Studio built, from an origin that frame can have" (a registered frame's window plus its possible origins, the opaque one included for a sealed frame) is exported as fromStudioPreview. Playback mirroring already used it.
  • overlayFrameLoop: wakes on a preview post only when fromStudioPreview accepts it, instead of on any post from Studio's own origin. A sealed frame's posts now wake the overlays, and a same-origin window that is not the preview frame no longer does.
  • The captions test's port tap, which holds the frame's answers until a test releases them, moves into the shared sealed-frame test helper so the crop test can use it too.

Before

Sealed preview on main, 3x close-ups of the crop frame (150 px crop on the right).

Layer whose scale tweens from 1 to 1.5, picked in the Layers panel at 3.5 s with no press on the canvas: the crop line is drawn at scale 1 (outline 36 px; unsealed 23 px).

Before: Layers pick, sealed main

Layer whose width tweens, selected at 1 s, then a seek to 3.5 s: the crop line keeps the size from before the seek (outline 31 px; unsealed 36 px), and the box only follows after the overlays' idle poll (2008 ms in this run).

Before: seek, sealed main

After

Sealed preview with this change, same walks: both match unsealed.

Layers pick: outline 23 px, as unsealed.

After: Layers pick, sealed

Seek: outline 36 px, settled 27 ms after the seek (unsealed: 28 ms).

After: seek, sealed

Unsealed, for reference:

Unsealed: Layers pick
Unsealed: seek

Test plan

  • Unit tests added/updated
  • Manual testing performed
  • Documentation updated (if applicable)
  • Comments follow CONTRIBUTING.md "Comments": they say why, not what, and a bug fix says what the code must do and how to reproduce the bug

DomEditCropHandles.sealed.test.ts:

  • "draws a sealed scaled card's crop insets at the card's own scale before any press"
  • "re-reads a sealed card's size when it changes while selected, before any press"
  • "draws a card selected again by its newest size, not by a read sent before it was left" (the frame's answer to the first selection is held until the card has been selected again)

LayersPanel.opaque.test.ts:

  • "draws the crop of a sealed scaled layer picked in the Layers panel at the layer's own scale" (the selection the panel makes, with no press on the canvas)

overlayFrameLoop.test.ts:

  • "wakes to full rate when a sealed preview Studio built reports a new frame from its opaque origin"
  • "ignores an opaque-origin preview post from a frame Studio did not build"
  • "ignores a same-origin preview post from a window that is not the preview frame Studio built"

fails without the fix:

  • with DomEditCropHandles.tsx as on main, the three crop rows and the Layers panel row fail (the outline is 380 px where 360 px is right);
  • with the first version of the read (keyed by element, keeping the first reply), "re-reads a sealed card's size…" and "draws a card selected again…" fail (540 px where 560 px is right);
  • with overlayFrameLoop.ts and bridgePlayback.ts as on main, "wakes to full rate when a sealed preview…" (1 frame, more than 5 wanted) and "ignores a same-origin preview post from a window…" (13 frames, at most 2 wanted) fail.

The new and changed tests pass three runs in a row; the push gate's covering run (39 Studio test files), Studio tsc and the Fallow audit pass.

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 271 (base branch 271), smooth 59 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (0)

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Refresh the local crop frame when a seek changes scale without resizing the painted box. In packages/studio/src/components/editor/DomEditCropHandles.tsx:194, the passive measurement is keyed to rounded overlay width and height. A seek can change the layer's intrinsic size and transform together, leaving that key unchanged. The overlay wakes, but the crop keeps its previous local scale.

I extended the sealed-frame fixture with a 200×100 layer at 2× and a 20 px right inset. After measurement, I moved it to 400×200 at 1×, leaving the same 400×200 painted box. The outline stayed at 360 px where the current inset should give 380 px. Refresh on a trusted seek or include the current local dimensions in the invalidation signal. Keep the existing one-read-at-a-time and stale-reply guards.

All 37 focused tests and the required captures check passed. The additional probe reproduced the stale outline in the sealed-frame fixture, without a full Studio browser walk.

— tai (automated review)

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 — Refresh the crop after the sealed frame applies the seek. DomEditCropHandles.tsx keys the new read on Studio’s local currentTime. The sealed adapter posts the seek to the frame, then Studio updates the store before the frame confirms that it has applied the seek. The geometry read is on the editing port and can still measure the old frame. When the seek lands with the same painted width and height, the overlay can wake without changing any dependency of the crop read.

I ran the three focused suites (33 passing), then exercised the existing sealed-frame fixture with the new playhead value arriving before the frame updated its geometry. The old read was still accepted and the outline stayed at 360 px instead of 380 px, even after an overlay render with the same outer box. The new test paints before updating the store, so it misses this ordering. Please re-read after the frame confirms the seek (or tie the read to the frame’s applied seek) and cover the delayed-paint order.

— tai (automated review)

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The crop refresh now waits for the registered preview frame’s accepted paused-time report. The held-seek test confirms that moving Studio’s playhead alone leaves the crop at its old scale and that the frame’s report refreshes it at the new scale. The 33 focused tests and required CI checks passed.

— tai (automated review)

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 22, 2026
Merged via the queue into main with commit 05d1bc8 Nov 22, 2026
78 checks passed
@miguel-heygen
miguel-heygen deleted the fix/sealed-crop-scaled-before-press branch November 22, 2026 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants